<template>
  <div class="analysis-progress" :class="{ show: show }">
    <div class="progress-container">
      <div class="steps-container">
        <div 
          v-for="step in steps" 
          :key="step.id"
          class="step"
          :class="{
            'completed': isStepCompleted(step.id),
            'current': step.id === currentStepId
          }"
        >
          <div class="step-icon">
            <i class="fas fa-check"></i>
          </div>
          <div class="step-content">
            <h4>{{ step.name }}</h4>
            <p>{{ step.description }}</p>
          </div>
        </div>
      </div>
      <div class="progress-bar">
        <div class="progress-fill" :style="{ width: `${progress}%` }"></div>
      </div>
    </div>
  </div>
</template>


<script setup lang="ts">
import { computed } from 'vue';
import type { AnalysisStep } from '../../api/dialogueAnalyze';


const props = defineProps<{
  steps: AnalysisStep[];
  currentStepId: string | null;
  show: boolean;
}>();


const progress = computed(() => {
  if (!props.currentStepId) return 0;
  const currentIndex = props.steps.findIndex(step => step.id === props.currentStepId);
  return ((currentIndex + 1) / props.steps.length) * 100;
});


const isStepCompleted = (stepId: string) => {
  if (!props.currentStepId) return false;
  const currentIndex = props.steps.findIndex(step => step.id === props.currentStepId);
  const stepIndex = props.steps.findIndex(step => step.id === stepId);
  return stepIndex < currentIndex;
};
</script>


<style scoped>
.analysis-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  transform: translateY(-100%);
  transition: transform 0.3s ease-in-out;
  z-index: 999; /* 确保在聊天窗口下面 */
}


.analysis-progress.show {
  transform: translateY(0);
}


.progress-container {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}


.steps-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}


.step {
  position: relative;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  transition: all 0.3s ease;
}


.step.completed {
  background: #f0f4ff;
}


.step.current {
  background: #f0f4ff;
  border: 1px solid #7c4dff;
}


.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
  color: #666;
  transition: all 0.3s ease;
}


.step.completed .step-icon {
  background: #7c4dff;
  color: white;
}


.step.current .step-icon {
  background: #7c4dff;
  color: white;
  animation: pulse 2s infinite;
}


.step-content h4 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: #333;
  transition: color 0.3s ease;
}


.step.completed .step-content h4,
.step.current .step-content h4 {
  color: #7c4dff;
}


.step-content p {
  margin: 0;
  font-size: 0.875rem;
  color: #666;
  line-height: 1.4;
}


.progress-bar {
  height: 4px;
  background: #e0e0e0;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 1rem;
}


.progress-fill {
  height: 100%;
  background: #7c4dff;
  transition: width 0.3s ease;
}


@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(124, 77, 255, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(124, 77, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(124, 77, 255, 0);
  }
}


@media (max-width: 768px) {
  .analysis-progress {
    padding: 1rem;
  }


  .steps-container {
    grid-template-columns: 1fr;
    gap: 1rem;
  }


  .step {
    display: flex;
    align-items: center;
    padding: 0.75rem;
  }


  .step-icon {
    margin: 0 1rem 0 0;
  }


  .step-content {
    flex: 1;
  }


  .step-content h4 {
    font-size: 0.875rem;
  }


  .step-content p {
    font-size: 0.75rem;
  }
}
</style>